export async function handleServiceResult(error, data) {
    if (error) {
        const fail = {
            error,
            result: data
        }
        return fail
    }
    const success = {
        error: null,
        result: data
    }
    return success
}

export function adapter(adapterFun, ...args) {
    let result

    const hasError = args.some((item) => {
        const flag = Boolean(item.error)
        if (flag) {
            result = {
                error: item.error,
                result: null
            }
        }
        return flag
    })

    if (!hasError) {
        const adapterFunArgs = args.map((item) => item.result)
        result = {
            error: null,
            result: adapterFun(...adapterFunArgs)
        }
    }

    return result
}
